<template>
  <div class="">
    <h2>点击变色</h2>
    <ul>
      <li
        v-for="i in 10"
        :key="i"
        @click="change(i)"
        :class="{ bg: flag == i }"
      >
        {{ i }}
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      flag: -1,
    };
  },
  mounted() {},
  methods: {
    change(i) {
      this.flag = i;
    },
  },
  components: {},
};
</script>

<style lang="scss">
.bg {
  background: red;
}
</style>
